<template>
    <view class="g_content content_box">
        <view class="bg"></view>
        <view class="content p_20">
            <view class=" f_s_20 m_t_50 m_l_10">
                <view >嗨，您 好</view>
                <view class="m_t_5">欢迎您使用困境儿童蜕变帮扶计划</view>
            </view>
            <view class="card_box p_20 p_b_20 m_t_50" style="width: 85vw">
                <view class="dis_f_c_c">
                    <u-button type="success" color="#FCE4E0" shape="circle"  @click="handleLogin">微信一键登录</u-button>
                </view>
                <view class="dis_f_r_c m_t_10">
                    <u-checkbox-group
                        size="16"
                        v-model="checkboxValue"
                        placement="column"
                    >
                        <u-checkbox
                            activeColor="#FCE4E0"
                            label=" "
                            name="agreement"
                        >
                        </u-checkbox>
                    </u-checkbox-group>
                    <view class="f_s_14 c_blue"> <text  @click="handleToProtocol(2)"> 《用户协议》</text></view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import {loginApi} from "@/sheep/api/login";
import {bindAgentId} from '@/sheep/utils/common'

export default {
    data() {
        return {
            checkboxValue: [],
        };
    },
    methods: {
        handleToProtocol(e){
            uni.navigateTo({
                url: '/pages/agreement/index?type='+e
            })
        },
        handleLogin() {
            if (this.checkboxValue.length==0){
                uni.showToast({
                    title: '请勾选用户协议',
                    icon: 'none'
                })
                return
            }
            let loginBody = {
                xcxCode: "",
                isBindPhone: false,
                clientId: "be7052a7e4f802c20df10a8d131adb12",
                grantType: "xcx",
                tenantId: "000000",
            };
            uni.login({
                provider: "weixin",
                success: function (loginRes) {
                    loginBody.xcxCode = loginRes.code;
                    loginApi(loginBody).then((res) => {
                        if (res.code === 200) {
                            uni.setStorageSync('token',res.data.access_token)
                            if (uni.getStorageSync('bindAgentId')) bindAgentId()
                            uni.switchTab({
                                url: "/pages/index/index",
                            })
                        }
                    });
                },
                fail(res) {
                    console.log(res, "登录失败");
                },
            });
        }
    },
};
</script>

<style lang="scss" scoped>
/deep/.u-button--circle{
    color: #000!important;
}
.content_box {
    position: relative;
    .bg {
        background: #FCE4E0;
        height: 30vh;
        border-bottom-right-radius: 118rpx;
    }

    .content {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
    }
}

</style>
